﻿using System.Web.UI;

namespace TemplateFoundation.UI.WebControls
{
    /// <summary>
    /// Templated control used to add controls which appear as page property controls when rendered, including name and description
    /// </summary>
    public class PagePropertyStyleControl : PagePropertyStyleControlBase
    {
        private ControlCollection _innerControls;

        /// <summary>
        /// Instantiates the ControlsTemplate template as the property control
        /// </summary>
        /// <returns></returns>
        public override Control CreatePropertyControl()
        {
            if (ControlsTemplate!=null)
            {
                var control = new Control();

                ControlsTemplate.InstantiateIn(control);

                _innerControls = control.Controls;

                return control;
            }

            return new LiteralControl {Text = "No content template specified"};
        }

        /// <summary>
        /// Template for controls to render as the property control(s)
        /// </summary>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public ITemplate ControlsTemplate { get; set; }

        /// <summary>
        /// Gets the controls inside the ControlsTemplate
        /// </summary>
        public ControlCollection InnerControls
        {
            get
            {
                return _innerControls;
            }
        }
    }
}
